package com.chuangjiangx.member.manager.client.web.basic.controller;

import com.chuangjiangx.commons.response.Response;
import com.chuangjiangx.commons.response.ResponseUtils;
import com.chuangjiangx.member.basic.ddd.dal.dto.StoreList;
import com.chuangjiangx.member.coupon.ddd.query.MbrCouponQuery;
import com.chuangjiangx.member.manager.basic.web.interceptor.Login;
import com.chuangjiangx.member.manager.common.Constants;
import com.chuangjiangx.member.manager.common.ThreadLocalUser;
import com.sun.jmx.snmp.ThreadContext;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cj-ch
 * @date 2018/10/20 下午5:00
 */
@RestController
@Api(value = "商户信息",tags = "商户")
@RequestMapping(method = RequestMethod.POST,value = "/mbr/merchant",produces = "application/json;charset=UTF-8")
public class MbrMerchantClientController {
    @Autowired
    private MbrCouponQuery mbrCouponQuery;
    /**
     * 加载商户下门店
     * @param name 门店名称
     * @return com.chuangjiangx.commons.response.CamelResponse
     * @map data
     * @see StoreList
     */
    @RequestMapping(value = "/store-list")
    @Login
    public Response listStoreForMerchant(String name, Integer type) {
        ThreadLocalUser token = (ThreadLocalUser) ThreadContext.get(Constants.CURRENT_LOGIN_USER_KEY);
        List<StoreList> storeList = mbrCouponQuery.findStoreListByMerchantId(token.getMerchantId(),name);
        //当type==1时,需要包含商户主账号信息
        if(type!=null){
            if(type==1){
                StoreList store = new StoreList();
                store.setId(-1L);
                store.setName("商户主账号");
                storeList.add(store);
            }
        }
        return ResponseUtils.successCamel(storeList);
    }
}
